﻿using System.Text;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Shard.Contracts;
using Shard.Contracts.SqlSugarConnect;
using SqlSugar;
using Volo.Abp.Domain.Repositories;
using System.Reflection;
using Shared.SqlSugarCore.Repository;
using Volo.Abp.Data;
using Volo.Abp.Domain;

namespace Shared.SqlSugarCore;

[DependsOn(typeof(AbpDddDomainModule))]
public class SqlSugarModule : AbpModule
{
    public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
    {
        var services = context.Services;
        var configuration = services.GetConfiguration();
        Configure<DbConnOptions>(configuration.GetSection("DbConnOptions"));

        //默认基础配置
        services.TryAddScoped<ISqlSugarDbContext, SqlSugarDbContext>();
        // 注册SqlSugar仓储基类
        context.Services.AddTransient(typeof(IRepository<>), typeof(SqlSugarRepository<>));
        context.Services.AddTransient(typeof(IRepository<,>), typeof(SqlSugarRepository<,>));
        // 注册自定义基类
        context.Services.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
        context.Services.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));

        return Task.CompletedTask;
    }

   
}